package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) values (#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    void add(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);

    @Select("select * from address_book where user_id=#{id} and is_default=1")
    AddressBook getDefault(Long id);

    //  @Update("update address_book set sex=#{sex},phone=#{phone}, city_code=#{cityCode}, city_name=#{cityName}, district_code=#{districtCode}, district_name=#{districtName}, detail=#{detail}, label=#{label}, is_default=#{isDefault} ,province_code=#{provinceCode}, province_name=#{provinceName} where id=#{id}")
    @Update("update address_book set sex=#{sex},label=#{label},phone=#{phone} ,detail=#{detail},consignee=#{consignee},city_code=#{cityCode}, city_name=#{cityName}, district_code=#{districtCode} , district_name=#{districtName}, province_code=#{provinceCode}, province_name=#{provinceName}  where id=#{id}")
    void update(AddressBook addressBook);


    @Delete("delete from address_book where id=#{id}")
    void delete(Long id);

    @Select("select * from  address_book where id=#{id}")
    AddressBook get(Long id);

    @Update("update address_book set is_default=1 where id=#{id}")
    void setdefault(Integer id);
}
